package com.onlinelearn.notifyservice.service;

import com.onlinelearn.notifyservice.model.NotificationType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Service
public class NotificationTriggerService {
    private final NotificationService notificationService;

    @Autowired
    public NotificationTriggerService(NotificationService notificationService) {
        this.notificationService = notificationService;
    }

    public void triggerHomeworkGradedNotification(Long studentId, Long homeworkId, Integer score) {
        String content = String.format("您的作业(ID:%d)已批改，得分：%d分", homeworkId, score);
        notificationService.sendNotification(
            studentId, 
            NotificationType.HOMEWORK_GRADED, 
            content
        );
    }

    public void triggerCourseUpdateNotification(Long courseId, String updateDetails) {
        // 获取课程所有学生
        // 实际实现需要从课程服务获取学生列表
        // 这里仅作示例
        Long studentId = 1L;
        
        String content = String.format("课程(ID:%d)有新的更新：%s", courseId, updateDetails);
        notificationService.sendNotification(
            studentId, 
            NotificationType.COURSE_UPDATED, 
            content
        );
    }

    public void triggerPaymentSuccessNotification(Long studentId, Long courseId, BigDecimal amount) {
        String content = String.format("课程(ID:%d)支付成功，金额：%.2f元", courseId, amount);
        notificationService.sendNotification(
            studentId, 
            NotificationType.PAYMENT_SUCCESS, 
            content
        );
    }

    public void triggerDeadlineReminderNotification(Long studentId, Long homeworkId, LocalDateTime deadline) {
        String content = String.format("作业(ID:%d)截止日期即将到来，请尽快提交！截止时间：%s", 
            homeworkId, 
            deadline.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
        );
        notificationService.sendNotification(
            studentId, 
            NotificationType.DEADLINE_REMINDER, 
            content
        );
    }
} 